#ifndef __eeprom_c__ruffi__eurobot08_
#define __eeprom_c__ruffi__eurobot08_

#include <avr/interrupt.h>
#include <avr/io.h>
unsigned int eepromwritecount = 0;
/*
* Pri spusteni programu se vynuluje pocitadlo zapisu do eepromu (eepromwritecount)
* Lze zapisovat data ve formatu unsigned char,
* nejlepe je ulozit do to_log z dim.c a pak vypsat pomoci log_to_eeprom(to_log);
* Po uspesnem zapsani vraci program 0. Pokud uz je pamet plna, vrati 1.
* Cteni dat probiha pres programator: Device-Read-Read Data.
*/
int log_to_eeprom(unsigned char ucData) {
	if ( eepromwritecount < 512) {
		char cSREG;
		cSREG = SREG;
		cli();
		
		/* Wait for completion of previous write */
		while(EECR & (1<<EEWE))
			;
		/* Set up address and data registers */
		EEAR = eepromwritecount;
		EEDR = ucData;
		/* Write logical one to EEMWE */
		EECR |= (1<<EEMWE);
		/* Start eeprom write by setting EEWE */
		EECR |= (1<<EEWE);
		
		eepromwritecount++;
		SREG = cSREG;
		return ( 0 );
	} else {
		return ( 1 );
	}
}
#endif
